//文档加载完成后执行其中的代码
$(function () {
});

function openVideo(fileItem) {
    const fileModal = new bootstrap.Modal($('#videoModal'));
    // 将参数存储在一个数据属性中
    $('#videoModal').data('fileItem', fileItem);
    fileModal.show();
}

//图集 当 show 实例方法被调用之后，此事件被立即触发。
$(function () {
    $('#videoModal').on('show.bs.modal', function (event) {
        // 从数据属性中获取参数
        const fileItem = $('#videoModal').data('fileItem');
        let videoUrl = fileItem.fileUrl
        console.log(videoUrl)
        const h = document.documentElement.clientHeight

        let video = videojs('vid');
        video.height(h);
        video.src(videoUrl)
        video.load(videoUrl)
        video.volume(1);
        video.play()


        // 调整视频大小以适应容器和窗口
        function resizeVideo() {
            const videoContent = document.documentElement
            const video = document.getElementById('vid');
            const containerWidth = videoContent.clientWidth;
            const containerHeight = videoContent.clientHeight;
            video.style.width = containerWidth + 'px';
            video.style.height = containerHeight + 'px';
        }

        window.addEventListener('resize', resizeVideo);
        resizeVideo();
    })
});

//当隐藏时触发
$(function () {
    $('#videoModal').on('hide.bs.modal', function () {
        let video = videojs('vid');
        video.pause()
        //$('#videoContent').innerHTML = ''; // 清空内容
        $('#videoModal').data('fileItem', null);
    })
});
